home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / freeres / freeres.pas next >
Pascal/Delphi Source File  |  1995-12-22  |  2KB  |  66 lines

  1. unit FreeRes;
  2. { ********************************************************************
  3.   This unit can be used to free windows resources otherwise consumed
  4.   by non-visible controls.  If you use it on visible controls, they
  5.   will disappear, but not know it.  It makes use of a protected method
  6.   of TWinControl, DestroyHandle.  This unit exports one procedure,
  7.   FreeWinControl.  This procedure takes a TWinControl as a parameter
  8.   and frees its resources.
  9.  
  10.   Released to the public domain on 8/21/1995
  11.   Jim Seach
  12.   Compuserve - 76012,3614
  13.   internet   - jseach@ix.netcom.com
  14.  
  15.  ******************************************************************* }
  16.  
  17. interface
  18.  
  19. uses Controls, ExtCtrls;
  20.  
  21. procedure FreeWinControl(WC : TWinControl);
  22.  
  23. implementation
  24.  
  25. { ================================================================== }
  26. { This is a "cousin" Class of TWinControl.  It is used to get around
  27.   the fact that DestroyHandle is protected }
  28.  
  29. Type
  30.  
  31.   TMyWinControl = Class(TWinControl)
  32.   public
  33.     procedure FreeResources;
  34.   end;
  35.  
  36. procedure TMyWinControl.FreeResources;
  37. begin
  38.   DestroyHandle;
  39. end; {procedure FreeResources}
  40.  
  41. { ================================================================== }
  42.  
  43. procedure FreeWinControl(WC : TWinControl);
  44. var
  45.   IsWinControl : boolean;
  46.   ThisControl  : integer;
  47. begin
  48.   {check to make sure WC is really a TWinControl}
  49.   try
  50.     if WC is TWinControl then
  51.       IsWinControl := True
  52.     else
  53.       IsWinControl := False;
  54.   except
  55.     { Catch the exception which will occur if WC is not an object}
  56.     IsWinControl := False;
  57.   end;
  58.  
  59.   {it is a TWinControl, so lets free its resources}
  60.   if IsWinControl then
  61.     TMyWinControl(WC).FreeResources;
  62.  
  63. end; {procedure FreePage}
  64.  
  65. end.
  66.